package GUI;

import Kernel.Billet;
import Kernel.Client;
import Kernel.ProfilPassager;
import Kernel.Trajet;

public class Etape2_Bus extends javax.swing.JFrame {
    

	private static final long serialVersionUID = 1L;
	private Trajet t;
	private Client ct;
    
    /** Crée une nouvelle instance de Etape2_Bateau paramétrée */
    public Etape2_Bus() {
    	initComponents();
        t = new Trajet();
        ct = new Client();
        this.setLocationRelativeTo(this.getParent());
    }
    
  
    /**
     * Crée une nouvelle instance de Etape2_Bateau paramétrée
     * @param t représente le trajet sélectionné avant
     */
    public Etape2_Bus(Trajet t){
    	 initComponents();
         this.t = t;
         ct = new Client();
         this.jTextField_infoType.setText(t.getTypeDeBase());
         this.jTextField_infoType.setEditable(false);
         if(this.jTextField_infoType.getText().compareTo("Non modifiable")==0)
         		this.jCheckBox_modif.setEnabled(true);
         else this.jCheckBox_modif.setEnabled(false);
         this.setLocationRelativeTo(this.getParent());
    }
    
    /**
  	 * Initialisation des composants d'AWT.
  	 */
    private void initComponents() {

        jLabel_Etape2 = new javax.swing.JLabel();
        jLabel_type = new javax.swing.JLabel();
        jTextField_infoType = new javax.swing.JTextField();
        jCheckBox_modif = new javax.swing.JCheckBox();
        jComboBox_typePassager = new javax.swing.JComboBox();
        jCheckBox_repas = new javax.swing.JCheckBox();
        jCheckBox_fidelite = new javax.swing.JCheckBox();
        jButton_retour = new javax.swing.JButton();
        jButton_suivant = new javax.swing.JButton();
        jLabel_typeP = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel_Etape2.setText("Etape 2 - Bus :");

        jLabel_type.setText("Type de billet proposé :");

        jCheckBox_modif.setText("Rendre modifiable");

        jComboBox_typePassager.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Adulte", "Enfant", "Enfant non-accompagné", "Etudiant", "Jeune", "Senior" }));

        jCheckBox_repas.setText("Repas");

        jCheckBox_fidelite.setText("Carte de fidélité");

        jButton_retour.setText("Retour");
        jButton_retour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_retourActionPerformed(evt);
            }
        });

        jButton_suivant.setText("Suivant");
        jButton_suivant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_suivantActionPerformed(evt);
            }
        });

        jLabel_typeP.setText("Type de passager :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton_retour)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_suivant)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel_typeP)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox_typePassager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(205, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel_type)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_infoType, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                        .addComponent(jCheckBox_modif)
                        .addGap(25, 25, 25))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel_Etape2)
                        .addContainerGap(459, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBox_repas)
                        .addGap(96, 96, 96)
                        .addComponent(jCheckBox_fidelite)
                        .addContainerGap(255, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel_Etape2)
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_type)
                    .addComponent(jTextField_infoType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox_modif))
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_typeP)
                    .addComponent(jComboBox_typePassager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(61, 61, 61)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox_fidelite)
                    .addComponent(jCheckBox_repas))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_suivant)
                    .addComponent(jButton_retour))
                .addContainerGap())
        );

        pack();
    }                   

                                             
    
    private void jButton_retourActionPerformed(java.awt.event.ActionEvent evt) {                                               
    	Etape11 e = new Etape11();
    	this.setVisible(false);
    	e.setVisible(true);
        
        this.dispose();
    }                                              

    private void jButton_suivantActionPerformed(java.awt.event.ActionEvent evt) {
    	// On enregistre les différentes informations dans un billet
    	Billet billet;
    	String typePassager = jComboBox_typePassager.getSelectedItem().toString();
    	if(typePassager.compareTo("Enfant non-accompagné") == 0){
    		billet = new Billet(ProfilPassager.valueOf("ENFANT_NON_ACCOMPAGNE"), ct ,  t);
    	}
    	else {
    		billet = new Billet(ProfilPassager.valueOf(typePassager.toUpperCase()), ct ,  t);
    	}
        // Modifiable
        billet.setModifier(jCheckBox_modif.isSelected());
        // Repas
        billet.setRepas(jCheckBox_repas.isSelected());
        //Carte de fidélité
        billet.setCarteFidelite(jCheckBox_fidelite.isSelected());
        
        // On affiche la fenêtre suivante
        Bilan b = new Bilan(this.t,billet);
        this.setVisible(false);
        b.setVisible(true);
        
    }  
    
    private javax.swing.JButton jButton_retour;
    private javax.swing.JButton jButton_suivant;
    private javax.swing.JCheckBox jCheckBox_fidelite;
    private javax.swing.JCheckBox jCheckBox_modif;
    private javax.swing.JCheckBox jCheckBox_repas;
    private javax.swing.JComboBox jComboBox_typePassager;
    private javax.swing.JLabel jLabel_Etape2;
    private javax.swing.JLabel jLabel_type;
    private javax.swing.JLabel jLabel_typeP;
    private javax.swing.JTextField jTextField_infoType;    
    
}
